home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / hashlib.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  4KB  |  142 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''hashlib module - A common interface to many hash functions.
  5.  
  6. new(name, string=\'\') - returns a new hash object implementing the
  7.                        given hash function; initializing the hash
  8.                        using the given string data.
  9.  
  10. Named constructor functions are also available, these are much faster
  11. than using new():
  12.  
  13. md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
  14.  
  15. More algorithms may be available on your platform but the above are
  16. guaranteed to exist.
  17.  
  18. NOTE: If you want the adler32 or crc32 hash functions they are available in
  19. the zlib module.
  20.  
  21. Choose your hash function wisely.  Some have known collision weaknesses.
  22. sha384 and sha512 will be slow on 32 bit platforms.
  23.  
  24. Hash objects have these methods:
  25.  - update(arg): Update the hash object with the string arg. Repeated calls
  26.                 are equivalent to a single call with the concatenation of all
  27.                 the arguments.
  28.  - digest():    Return the digest of the strings passed to the update() method
  29.                 so far. This may contain non-ASCII characters, including
  30.                 NUL bytes.
  31.  - hexdigest(): Like digest() except the digest is returned as a string of
  32.                 double length, containing only hexadecimal digits.
  33.  - copy():      Return a copy (clone) of the hash object. This can be used to
  34.                 efficiently compute the digests of strings that share a common
  35.                 initial substring.
  36.  
  37. For example, to obtain the digest of the string \'Nobody inspects the
  38. spammish repetition\':
  39.  
  40.     >>> import hashlib
  41.     >>> m = hashlib.md5()
  42.     >>> m.update("Nobody inspects")
  43.     >>> m.update(" the spammish repetition")
  44.     >>> m.digest()
  45.     \'\\xbbd\\x9c\\x83\\xdd\\x1e\\xa5\\xc9\\xd9\\xde\\xc9\\xa1\\x8d\\xf0\\xff\\xe9\'
  46.  
  47. More condensed:
  48.  
  49.     >>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
  50.     \'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2\'
  51.  
  52. '''
  53. __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
  54. algorithms = __always_supported
  55. __all__ = __always_supported + ('new', 'algorithms')
  56.  
  57. def __get_builtin_constructor(name):
  58.     
  59.     try:
  60.         if name in ('SHA1', 'sha1'):
  61.             import _sha as _sha
  62.             return _sha.new
  63.         if None in ('MD5', 'md5'):
  64.             import _md5 as _md5
  65.             return _md5.new
  66.         if None in ('SHA256', 'sha256', 'SHA224', 'sha224'):
  67.             import _sha256 as _sha256
  68.             bs = name[3:]
  69.             if bs == '256':
  70.                 return _sha256.sha256
  71.             if None == '224':
  72.                 return _sha256.sha224
  73.         if name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
  74.             import _sha512 as _sha512
  75.             bs = name[3:]
  76.             if bs == '512':
  77.                 return _sha512.sha512
  78.             if None == '384':
  79.                 return _sha512.sha384
  80.     except ImportError:
  81.         pass
  82.  
  83.     raise ValueError('unsupported hash type ' + name)
  84.  
  85.  
  86. def __get_openssl_constructor(name):
  87.     
  88.     try:
  89.         f = getattr(_hashlib, 'openssl_' + name)
  90.         f()
  91.         return f
  92.     except (AttributeError, ValueError):
  93.         return __get_builtin_constructor(name)
  94.  
  95.  
  96.  
  97. def __py_new(name, string = ''):
  98.     """new(name, string='') - Return a new hashing object using the named algorithm;
  99.     optionally initialized with a string.
  100.     """
  101.     return __get_builtin_constructor(name)(string)
  102.  
  103.  
  104. def __hash_new(name, string = ''):
  105.     """new(name, string='') - Return a new hashing object using the named algorithm;
  106.     optionally initialized with a string.
  107.     """
  108.     
  109.     try:
  110.         return _hashlib.new(name, string)
  111.     except ValueError:
  112.         return __get_builtin_constructor(name)(string)
  113.  
  114.  
  115.  
  116. try:
  117.     import _hashlib
  118.     new = __hash_new
  119.     __get_hash = __get_openssl_constructor
  120. except ImportError:
  121.     new = __py_new
  122.     __get_hash = __get_builtin_constructor
  123.  
  124. for __func_name in __always_supported:
  125.     
  126.     try:
  127.         globals()[__func_name] = __get_hash(__func_name)
  128.     continue
  129.     except ValueError:
  130.         import logging
  131.         logging.exception('code for hash %s was not found.', __func_name)
  132.         continue
  133.     
  134.  
  135.  
  136. del __always_supported
  137. del __func_name
  138. del __get_hash
  139. del __py_new
  140. del __hash_new
  141. del __get_openssl_constructor
  142.